package com.lemon.components.ant.util.freemarker;

import java.util.List;

import freemarker.template.SimpleNumber;
import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

public class JdbcTypeParse2Java implements TemplateMethodModelEx {

	@Override
	public Object exec(List arguments) throws TemplateModelException {
		String jdbcType = String.valueOf(arguments.get(0));
		SimpleNumber scaleNumber = (SimpleNumber)arguments.get(1);
		int scale = scaleNumber.getAsNumber().intValue();
		switch (jdbcType) {
			case "INT":
				return "Integer";
			case "BIGINT":
				return "Long";
			case "BIT":
				return "Boolean";
			case "DOUBLE":
				return "Double";
			case "FLOAT":
				return "Float";
			case "tinyint":
				if(scale == 1) {
					return "Boolean";
				} else {
					return "Integer";
				}
			case "VARCHAR":
			case "CHAR":
			case "LONGTEXT":
			case "MEDIUMTEXT":
			case "TEXT":
				return "String";
			case "DATE":
			case "DATETIME":
			case "TIMESTAMP":
				return "java.util.Date";
			case "DECIMAL":
				if(scale >= 8) {
					return "com.system.core.utils.DigitAssets";
				} else if(scale == 4) {
					return "com.system.core.utils.Money";
				} else {
					return "java.math.BigDecimal";
				}
			default:
				return jdbcType;
		}
	}

}
